package core;

import java.util.HashMap;
import java.util.List;

import main.SYRRES;

public class User {
	private String id;
	private HashMap<String, List<Integer>> biereNote;
	private int sumNote[] = new int[SYRRES.NB_NOTE];
	private double average[] = new double[SYRRES.NB_NOTE];
	
	public User(String id) {
		this.setId(id);
		setBiereNote(new HashMap<String, List<Integer>>());
		for (int i = 0; i < average.length; i++) {
			average[i] = -2;
		}
	}
	
	public void addBiereNote(String biere, List<Integer> note) {
		biereNote.put(biere, note);
	}

	public HashMap<String, List<Integer>> getBiereNote() {
		return biereNote;
	}
	
	public boolean hasBeer(String beerID) {
		return biereNote.keySet().contains(beerID);
	}

	public void setBiereNote(HashMap<String, List<Integer>> biereNote) {
		this.biereNote = biereNote;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}	
	
	public void calculSumNote(int noteID) {
		int sum = 0;
		for (List<Integer> notes : biereNote.values()) {
			sum += notes.get(noteID);
		}
		sumNote[noteID] = sum;
	}
	
	public int getSumNote(int noteID) {
		return sumNote[noteID];
	}
	
	public double getAverageNote(int noteID) {
		if (average[noteID] == -2) {
			average[noteID] = (double)sumNote[noteID] / biereNote.size();
		}
		return average[noteID];
	}
	
	public void addAverageNote(int noteID, double value) {
		average[noteID] += value;
	}
	
	public int getNote(String beerID, int noteID) {
		return biereNote.get(beerID).get(noteID);
	}
}
